from django.contrib import admin

# Register your models here.
from .models import Student, Question


# 如何将 咱们自己写的 模型 注册到后台

# admin.site.register(Student) # 最简单的注册方式
# admin.site.site_title = 'site_title'
# admin.site.site_header = 'site_header'
# admin.site.index_title = 'index_title'


# 第二种 装饰器注册方式
@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    # 展示数据 显示的字段
    # list_display = ['stu_name', 'sex', 'cls', 'subject']
    list_display = [x for x in list(Student._meta._forward_fields_map.keys())]
    # 后台添加 或者修改 学生信息
    # fields = ['stu_name', 'sex', 'cls']
    fields = [('stu_name', 'sex'), ('cls', 'subject')]

    # 先根据姓名 倒序排 再根据 专业正序排
    ordering = ['subject', '-stu_name']
    # date_hierarchy = 'created'

    # 过滤器
    list_filter = ['sex', 'subject']

    # 排除编辑字段 和fields正好相反, 和fields不同时 使用
    # exclude = ['img_path']


class QuestionAdmin(admin.ModelAdmin):
    # date_hierarchy = 'create_time'  # 日期分层

    list_per_page = 4
    search_fields = ['title', 'ref_answer']
    # list_max_show_all = 8


admin.site.register(Question, QuestionAdmin)
# 第一种注册方式
# admin.site.register(Student, StudentAdmin)
